package com.sky.controller.admin;

import com.sky.constant.ShopConstant;
import com.sky.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.*;

/**
 * ShopController
 *
 * @author liliudong
 * @version 1.0
 * @description 店铺控制器
 * @date 2023/7/31 15:28
 */
@RestController("adminShopController")
@RequestMapping("/admin/shop")
public class ShopController {

    @Autowired
    private RedisTemplate redisTemplate;


    /**
     * 状态
     *
     * @return {@link Result}<{@link Integer}>
     */
    @GetMapping("/status")
    public Result<Integer> status() {
        ValueOperations valueOperations = redisTemplate.opsForValue();
        Integer status = (Integer) valueOperations.get(ShopConstant.SHOP_STATUS);
        return Result.success(status);
    }

    /**
     * 更新状态
     *
     * @param status 状态
     * @return {@link Result}<{@link ?}>
     */
    @PutMapping("/{status}")
    public Result<?> updateStatus(@PathVariable Integer status) {
        ValueOperations valueOperations = redisTemplate.opsForValue();
        valueOperations.set(ShopConstant.SHOP_STATUS, status);
        return Result.success();
    }
}
